package com.imooc.bilibili.api;

import com.imooc.bilibili.domain.JsonResponse;
import com.imooc.bilibili.domain.Video;
import com.imooc.bilibili.service.ElasticSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
public class SystemController {

    @Autowired
    private ElasticSearchService elasticSearchService;

    @GetMapping("/contents")
    public JsonResponse<List<Map<String, Object>>> getEsVideos(@RequestParam String keyword,
                                           @RequestParam Integer pageSize,
                                           @RequestParam Integer pageNo) throws IOException {
        List<Map<String, Object>> contents = elasticSearchService.getContents(keyword, pageSize, pageNo);
        return new JsonResponse<>(contents);
    }

}
